package com.example.nacosconsumer.dao;

import com.example.nacosconsumer.pojo.Remark;
import com.example.nacosconsumer.pojo.tiezi;
import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ForumMapper {

    //查询所有帖子，并且返回一个帖子列表
    @Select("SELECT * FROM tiezi")
    Page<tiezi> select_tiezi();

    //根据用户存储帖子
    @Insert("INSERT INTO tiezi(user,content) VALUE(#{user},#{content})")
    void Save_tiezi(@Param("user") String user, @Param("content") String content);

    //获取所有评论(用于获取评论树)
    @Select("SELECT * FROM remark")
    List<Remark> selectRemark();

    //评论存储函数
    @Insert("INSERT INTO remark(User,Text,ParentID) VALUES(#{User},#{Text},#{ParentID})")
    void savaRemark(@Param("User") String User,@Param("Text") String Text,@Param("ParentID") Integer ParentID);
    //@Select("SELECT user FROM star where tieziID=#{tieziID}")
    //Set<String> selectStar(@Param("tieziID") Integer tieziID);
    //
    //@Select("SELECT statu FROM star where tieziID=#{tieziID}")
    //Integer getUserstarStatu(@Param("tieziID") Integer tieziID);

    //头像存储地址查询
    @Select("SELECT headshotPath FROM java_user WHERE user=#{user}")
    String getHeadshotPath(@Param("user") String user);

    @Select("<script>"
            + "SELECT * FROM tiezi WHERE ID IN "
            + "<foreach item='item' index='index' collection='list'      open='(' separator=',' close=')'>"
            + "#{item}"
            + "</foreach>"
            + "</script>")
    Page<tiezi> getFromID(@Param("list") List<Integer> list);

    @Update("update tiezi set starNum=#{starNum} where ID=#{ID}")
    void updateStarNum(String ID,long starNum);
}
